//
//  BAFoodMenuVC.m
//  YunFu
//
//  Created by Bager on 2018/9/5.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BAFoodMenuVC.h"

#import "BAFoodMenuCell.h"

@interface BAFoodMenuVC ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation BAFoodMenuVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createCollectionView];
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2 - 10) / 2.0, 140);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 10;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 10;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(10, kPublicMargin, 10, kPublicMargin);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)  collectionViewLayout:flowLayout];
    
    self.collection.backgroundColor = kPublicColorLightGray;
    
    self.collection.dataSource = self;
    
    self.collection.delegate = self;
    
    [self.collection registerClass:[BAFoodMenuCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    
    [self.view addSubview:self.collection];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    BAFoodMenuCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    cell.layer.cornerRadius = 4;
    cell.layer.masksToBounds = YES;
    
    NSArray *imgArray = @[@"12_pic5"];
    NSArray *nameArray = @[@"油焖大虾"];
    NSArray *detailArray = @[@"20人推荐"];
    NSArray *typeArray = @[@"¥ 50"];
    
    [cell.img setImage:[UIImage imageNamed:imgArray[0]]];
    cell.name.text = nameArray[0];
    cell.detail.text = detailArray[0];
    cell.type.text = typeArray[0];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.callBack)
    {
        self.callBack(scrollView);
    }
}



@end
